package com.smiletrain.view;

import java.util.List;

//import android.app.AlarmManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.smiletrain.R;
import com.smiletrain.base.Alarma;
import com.smiletrain.util.AdminAlarma;

public class ItemAlarm {

	public ItemAlarm(int id, String fecha, String hora) {
		this.setId(id);
		this.fecha = fecha;
		this.hora = hora;
	}
	
	public void generateView(final ViewGroup parent) {
		View rview = LayoutInflater.from(parent.getContext())
        		.inflate(R.layout.itemalarm, null);
        TextView tfecha = (TextView) rview.findViewById(R.id.iFecha);  
        tfecha.setText(fecha);
        TextView thora = (TextView) rview.findViewById(R.id.iHora);  
        thora.setText(hora);
        ImageView teliminar = (ImageView) rview.findViewById(R.id.iElminiar);
        teliminar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AdminAlarma.instance.eliminarAlarma(id);
				
				ListView listView = (ListView) parent.findViewById(R.id.listView1);
				
				List<Alarma> alarmas = AdminAlarma.instance.getAlarmas();
				
				ItemAlarm[] values = new ItemAlarm[alarmas.size()];
				
				int i = 0;
				for(Alarma a : alarmas){
					values[i] = new ItemAlarm(a.getId(), a.getFecha(), a.getHora() + " Hrs");
					i++;
				}

		        listView.setAdapter(new ListaAlarm(values));
				
//		        AlarmManager alarmManager = (AlarmManager) parent.getContext().getSystemService(android.content.Context.ALARM_SERVICE);
//				
//				// Levanta la alarma con el tiempo y la especificacion de que se va a lanzar
//				alarmManager
		        
			}
		});
        
        view = rview;
	}
	
	public void setBackground(int background) {
		view.findViewById(R.id.titulo).setBackgroundResource(background);
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String getFecha() {
		return fecha;
	}
	
	public void setFecha(String text) {
		this.fecha = text;
	}
	
	public String getHora() {
		return hora;
	}
	
	public void setHora(String text) {
		this.hora = text;
	}

	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}

	private int id = 0;
	private String fecha = "";
	private String hora = "";
	private View view = null;
	
}
